<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2017/4/2
 * Time: 22:45
 */

namespace Lib\Api;


class RebateRatioApi extends UtilsApi {
    private static $modelName = "RebateRatio";

    /** 获取交易明细列表
     * @param $where
     * @param $left
     * @param string $field
     * @param $group
     * @param $order
     * @return mixed
     */
    public static function getList($where, $left='', $field='*', $group='', $order='') {
        $model = M();
        $list = $model->table('fs_rebate_ratio a')
            ->join($left)
            ->field($field)
            ->where($where)
            ->group($group)
            ->order($order)
            ->select();
        // var_dump($list);
        return $list;
    }

    /**
     * 根据用户组交易总额获取返利规则
     * @param $sum_order_price
     * @return mixed
     */
    public static function getRebateRatioList($sum_order_price) {
        $model = M(RebateRatioApi::$modelName);
        $map = array();
        $map['conditions'] = array('elt', $sum_order_price);
        $rebate_ratio_list = $model->field('GROUP_CONCAT(rebate_ratio_layer, "|", rebate_ratio) as rebate_ratio')->order("conditions desc")->group("conditions")->where($map)->select();
        return $rebate_ratio_list;
    }

    public static function getRebateRatioByCondition($where, $field="*") {
        $model = M(RebateRatioApi::$modelName);
        return  $model->field($field)->where($where)->select();//page两个参数（页码，条数），不需要自己计算
    }

    /** 删除交易明细
     * @param $where
     */
    public static function delete($where) {
        parent::delete(RebateRatioApi::$modelName, $where);
    }

    /** 批量添加数据
     * @param $data
     * @return mixed
     */
    public static function addAll($data) {
        $model = M(RebateRatioApi::$modelName);
        return $model->addAll($data);
    }
}